import gensim
from gensim import models
from gensim.models import word2vec
import nltk
import os
import pandas as pd
from nltk.corpus.reader import lin
from nltk.util import transitive_closure
import numpy as np
from numpy.core.fromnumeric import size
import pandas as pd
from gensim.test.utils import common_texts
from gensim.models import Word2Vec
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from progress.bar import Bar
from gensim.models.word2vec import LineSentence
from tqdm import tqdm


class Solution():
    def __init__(self) -> None:
        self.corpus_path = "../processed_data/all_php.txt"
        self.model_path = "../processed_data/model"
        self.model = Word2Vec.load(self.model_path)

    def buidlWord2Vec(self):
        print('new_energy_sentences:')
        sentences = word2vec.Text8Corpus(self.corpus_path)
        model = Word2Vec(sentences, size=10, window=5, min_count=1, workers=4)
        print('Model save...')
        model.save(self.model_path)

    # 获得每个词的词向量
    def get_vec(self, model, word):
        vec = model.wv.vectors[model.wv.vocab[word].index]
        return vec

if __name__ == "__main__":
    ob = Solution()
    # ob.buidlWord2Vec()
    print(type(ob.get_vec(ob.model, "NOP")))